/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.opshowcase.schedulerservice1subsub.client.presenter;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;

import fr.openparts.OpenParts.client.OPBinder;
import fr.openparts.OpenParts.client.OPParams;
import fr.openparts.OpenParts.client.OPShell;
import fr.openparts.OpenParts.client.OPSlotProxy;
import fr.openparts.OpenParts.client.annotations.OPEventHandler;
import fr.openparts.OpenParts.client.annotations.OPServiceName;
import fr.openparts.OpenParts.client.annotations.OPViewFactory;
import fr.openparts.opshowcase.schedulerservice1subsub.client.view.SchedulerService1subsubView;

/**
 * Presenter of Scheduler Service 1 sub sub for Scheduler Module, for OpenParts Showcase
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 05 May 2011
 */
@OPServiceName("schedulerservice1subsub")
public class SchedulerService1subsubPresenter implements EntryPoint {

    public interface SchedulerService1subsubPresenterBinder extends OPBinder<SchedulerService1subsubPresenter> {}
    public final static SchedulerService1subsubPresenterBinder binder = GWT.create(SchedulerService1subsubPresenterBinder.class);

    protected SchedulerService1subsubView view;

    /**
     * Entry point, method called when the module is loaded.
     * 
     * @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
     */
    @Override
    public void onModuleLoad() {
        binder.bindPart(this);
        view = new SchedulerService1subsubView();
        log("service 1 sub sub loaded");
        binder.notifyLoadingCompleted();
    }

    /**
     * Returns the embedded view of this module
     * 
     * @param params
     *            not used here
     * @return the main view of this module
     */
    @OPViewFactory(resourceName = "schedulerservice1subsub", actionName = OPShell.ACTION_DISPLAY)
    public Widget getEmbeddedView(final OPParams params, final OPSlotProxy proxy) {
        log("service 1 sub sub view displayed");
        return view;
    }
    
    /**
     * Handle events.
     * 
     * @param event
     *            not used here
     * @param params
     *            not used here
     */
    @OPEventHandler("dummyEvent")
    public void handleEvent(final String event, final OPParams params) {
        log("service 1 sub sub handling event");
    }
    
    /**
     * Log message in the global view log
     */
    public void log(final String message) {
         final Element logContainer = DOM.getElementById("schedulerCommandsLogs");
         final Element messageContainer = DOM.createDiv();
         messageContainer.setInnerText("-> " + message);
         logContainer.appendChild(messageContainer);
    }

}
